import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HeroService } from '../../../../services/hero.service';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-maintinfo',
  templateUrl: './maintinfo.component.html',
  styleUrls: ['./maintinfo.component.css']
})
export class MaintinfoComponent implements OnInit {

  public data: Array<any> = [''];
  public datalist: Array<any> = [];
  public userinfo: string;
  public maintinfo: string;
  public radioValue: string = "1";
  public PageIndex: number = 1;
  public PageSize: number = 10;
  public PageTotal: number;
  constructor(private heroService: HeroService,
    private route: ActivatedRoute,
    private modalService: NzModalService) { }

  ngOnInit() {
    this.getRadioValue(true);
  }
  //监听数据
  getRadioValue(getInfo) {
    console.log(this.radioValue);
    const id = this.route.snapshot.paramMap.get('id');
    if (!getInfo) {
      getInfo = false;
    }
    if (this.radioValue == "1") {
      let url = host + "/main/merchantConnectMaint/info?id=" + id + "&getInfo=" + getInfo + "&statusArray=3" + "&page=" + this.PageIndex + "&pageSize=" + this.PageSize;
      this.heroService.get(url).then(result => {
        if (result.code == 0) {
          if (getInfo) {
            this.data[0] = result.data.bean;
          }
          this.maintinfo = result.data.connectMaint;
          this.userinfo = result.data.connectUser;
          this.datalist = result.data.taskOrderPageBean.result;
          this.PageIndex = result.data.taskOrderPageBean.curPage;
          this.PageTotal = result.data.taskOrderPageBean.totalRow;
        } else {
          this.modalService.error({
            nzTitle: '提示',
            nzContent: result.msg
          });
        }
      })
    }
    if (this.radioValue == "2") {
      let url = host + "/main/merchantConnectMaint/info?id=" + id + "&getInfo=" + getInfo + "&statusArray=1" + "&statusArray=2" + "&page=" + this.PageIndex + "&pageSize=" + this.PageSize;
      this.heroService.get(url).then(result => {
        if (result.code == 0) {
          if (getInfo) {
            this.data[0] = result.data.bean;
          }
          this.maintinfo = result.data.connectMaint;
          this.userinfo = result.data.connectUser;
          this.datalist = result.data.taskOrderPageBean.result;
          this.PageIndex = result.data.taskOrderPageBean.curPage;
          this.PageTotal = result.data.taskOrderPageBean.totalRow;
        } else {
          this.modalService.error({
            nzTitle: '提示',
            nzContent: result.msg
          });
        }
      })
    }
  }
  //分页
  PageIndexChange(event) {
    this.PageIndex = event;
    this.getRadioValue(false);
  }
}
